package com.it.d10_api_object;

// Cloneable 是一个标记接口；
// 规则。加上 implements Cloneable 才能使用clone() 克隆方法

public class User implements Cloneable { //  默认继承 extends Object
    private int id; // 编号
    private String username; //用户名
    private String password; // 密码
    private double[] scores; // 分数

    public User() {
    }

    public User(int id, String username, String password, double[] scores) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.scores = scores;
    }

    // 重写 克隆方法
    @Override
    protected Object clone() throws CloneNotSupportedException {
        // super 去调用父类Object中clone方法
//        return super.clone(); // 浅克隆

//        深克隆
        User u2 = (User) super.clone();
        u2.scores = u2.scores.clone();
        return  u2;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public double[] getScores() {
        return scores;
    }

    public void setScores(double[] scores) {
        this.scores = scores;
    }
}
